/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.sql.Timestamp;
import java.util.ArrayList;

/**
 *
 * @author SONY
 */
public class SaleOrderService {
    
    SaleOrderDAO saleOrderDAO;
    
    public SaleOrderService() {
        saleOrderDAO = new SaleOrderDAO();
    }
    
    public SaleOrder addSaleOrder(int MemberID, String Name, String Address, String Phone, Timestamp OrderDate, String Status, double Total, String PaymentType) {
        try {
            int saleorderid = saleOrderDAO.insert(MemberID, Name, Address, Phone, OrderDate, Status, Total, PaymentType);
            if (saleorderid != -1) {
                SaleOrder saleorder = new SaleOrder(saleorderid, MemberID, Name, Address, Phone, OrderDate, Status, Total, PaymentType);
                return saleorder;
            }
        } catch (Exception e) {
            System.err.println(e);
        }
        return null;
    }
    
    public ArrayList<SaleOrder> getSaleOrders_byMemberID(int MemberID) {
        ArrayList<SaleOrder> lstSaleOrders = new ArrayList<SaleOrder>();
        try {
            lstSaleOrders = saleOrderDAO.search_byMemberID(MemberID);
            
        } catch(Exception e) {
            System.err.println(e);
        }
        return lstSaleOrders;
    }
    
    public ArrayList<SaleOrder> getSaleOrders() {
        ArrayList<SaleOrder> SaleOrders = new ArrayList<SaleOrder>();
        try {
            SaleOrders = saleOrderDAO.getAllSaleOrders();
        } catch(Exception e) {
            System.err.println(e);
        }
        return SaleOrders;
    }
    
    public ArrayList<SaleOrder> getSaleOrders_bySaleOrderID(int SaleOrderID) {
        ArrayList<SaleOrder> lstSaleOrders = new ArrayList<SaleOrder>();
        try {
            lstSaleOrders = saleOrderDAO.search_bySaleOrderID(SaleOrderID);
            
        } catch(Exception e) {
            System.err.println(e);
        }
        return lstSaleOrders;
    }

    public boolean changeStatus(int SaleOrderID, String Status) {
        try {
            if(saleOrderDAO.update_Status(SaleOrderID, Status)) {
                return true;
            }
        } catch (Exception e) {
            System.err.println(e);
        }
        return false;
    }    
}
